<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [22, 3, 54, 12];
        arr.sort(); // 无参，默认按字符串排序
        console.log(arr);

        let arr1 = [22, 13, 4, 32];
        // 数字排序
       /*  arr1.sort(function (a, b) {
            return a - b;
        });
        console.log(arr1); */

        // 作业：对象的属性排序。
        // 商品的价格，距离，好评，综和
        var arr2 = ['99', '89', '79', '999', ];
        arr2.sort(function (a, b) {
            return a - b;
        });
        for(let impt of arr2){
              console.log(impt+'$');
        }
      


        // 好评
        var items = [{
                name: '四星好评',
                value: 2
            }, {
                name: '五星好评',
                value: 1
            },
            {
                name: '一星好评',
                value: 5
            },
            {
                name: '三星好评',
                value: 3
            },
            {
                name: '二星好评',
                value: 4
            },
            {
                name: '一星好评'
            },

        ];

        items.sort(function (a, b) {
            return (a.value - b.value)
        });
        for(let impt of items){
              console.log(impt);
        }
        console.log(items);
    </script>
</body>

</html>